﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;

public class EventManager<T>
{
    private static Dictionary<MyEventType, List<Action<T>>> eventDic = new Dictionary<MyEventType, List<Action<T>>>();
    /// <summary>
    /// 添加事件
    /// </summary>
    /// <param name="type"></param>
    /// <param name="act"></param>
    public static void AddEvent(MyEventType type, Action<T> act)
    {
        if (eventDic.ContainsKey(type))
        {
            if (!eventDic[type].Contains(act))
            {
                eventDic[type].Add(act);
            }
        }
        else
        {
            List<Action<T>> list = new List<Action<T>>();
            eventDic.Add(type, list);
            list.Add(act);
        }
    }

    /// <summary>
    /// 移除事件
    /// </summary>
    /// <param name="type"></param>
    public static void RemoveEvent(MyEventType type)
    {
        if (eventDic.ContainsKey(type))
        {
            eventDic.Remove(type);
        }
    }

    public static void RemoveEvent(MyEventType type, Action<T> act)
    {
        if (eventDic.ContainsKey(type))
        {
            if (eventDic[type].Contains(act))
            {
                eventDic[type].Remove(act);

            }
        }
    }

    /// <summary>
    /// 触发事件
    /// </summary>
    /// <param name="type"></param>
    /// <param name="data"></param>
    public static void TriggerEvent(MyEventType type, T data)
    {
        if (eventDic.ContainsKey(type))
        {
            List<Action<T>> list = eventDic[type];
            foreach (var callback in list)
            {
                callback(data);
            }
        }
    }
}

/// <summary>
/// 指示灯管理类
/// </summary>
public class Unit {
    public int i_index;   //指示灯的索引
    public string s_name; //指示灯的状态
    public Unit(int index, string name) {
        i_index = index;
        s_name = name;
    }
}
public enum MyEventType
{
    SiFangDirButtonClickEvent,      //“四方”设备的方向键事件
    UpButtonClickEvent,             
    DownButtonClickEvent,
    LeftButtonClickEvent,
    RightButtonClickEvent,
    QuitButtonClickEvent,           //“四方”设备的退出键事件
    SetButtonClickEvent,            //“四方”设备的设置键事件
    ZhishidengTypeEvent,            //“四方”设备的指示灯事件
    ChangeUIToShijianjiluEvent,     //改变“四方”设备的当前界面到“事件记录”界面
    XuanzhuanAnniuEvent,            //旋转按钮事件
    ChongzhiShujuEvent,             //重置“四方”设备的高亮选择框
    ResetButtonClickEvent,          //"信号复归"键事件
    SifangHeipingEvent,
    //OnllyUpButonClickEvent,
    //OnllyDownButonClickEvent,
    //OnllyLeftButonClickEvent,
    //OnllyRightButonClickEvent,
    OnllyDirButtonClickEvent,      //onlly设备方向键事件
    OnllyPageButtonClickEvent,     //onlly页面切换事件
    OnllyEnterButtonClickEvent,    //onlly“Enter”键事件
    OnllyStartButtonClickEvent,    //onlly“Start”键事件
    OnllyReSetPageEvent,           //重置Onlly设备界面的高亮为00
    OnllyNumberButtonClickEvent,   //onlly数字键事件
    OnllyXuanzhuan,                //旋转按钮旋转
    OnllyHeiPingEvent,
    OnllyResultEvent,               //结果界面事件
    OnllyAddReduceEvent,            //手控模式下可以在第一页控制变化的电流 
    OnllyEscButtonEvent             //在手控模式试验过程中按下出现退出试验弹框
}




